package com.duoduo.demo.springboot.job;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledJob {
	/**
	 * 延迟3秒执行，且执行1次
	 */
	// @Scheduled(initialDelay=3000)
	// 抛出异常Encountered invalid @Scheduled method 'runOnce': Exactly one of the 'cron', 'fixedDelay(String)', or 'fixedRate(String)' attributes is required
	// 必须至少有一个：'cron', 'fixedDelay(String)', or 'fixedRate(String)
	public void runOnce() {
		System.out.println(String.format("current timestamp = %d", System.currentTimeMillis()));
	}
	
	/**
	 * 延迟3秒执行，且 每365天执行1次
	 */
	@Scheduled(initialDelay=3000, fixedRate = 365 * 24 * 3600 * 1000)
	public void runEveryYear() {
		System.out.println(String.format("current timestamp = %d", System.currentTimeMillis()));
	}
}
